# -*- coding: utf8 -*-
# @author='dapeng',
# @version='1.0.0'
import urllib.request
import urllib.parse
import json


#知乎日报
def newszhihu():
    url = 'https://news-at.zhihu.com/api/4/stories/latest'
    f = urllib.request.urlopen(url)
    zhihujson = json.loads(f.read().decode('utf-8'))
    list = zhihujson.get('stories')
    str = []
    str.append("=======知乎日报=========\r\n")
    for story in list:
        str.append(story.get('title'))
        str.append('\r\n')
        str.append(story.get('url'))
        str.append('\r\n')
        str.append('********************\r\n')
    return (''.join(str))


#知乎历史
def historyzhihu(data):
    url = 'https://news-at.zhihu.com/api/4/stories/before/'+data
    f = urllib.request.urlopen(url)
    zhihujson = json.loads(f.read().decode('utf-8'))
    list = zhihujson.get('stories')
    str = []
    str.append("=======知乎往日=========\r\n")
    for story in list:
        str.append(story.get('title'))
        str.append('\r\n')
        str.append(story.get('url'))
        str.append('\r\n')
        str.append('********************\r\n')
    return (''.join(str))